<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./lib/jquery.js"></script>
</head>
<body>
    <form action="./index2.html" id="login">
        <div>
            用户名:
            <input type="text" name="uname">
            <span>帐号是否合法(字母开头，允许5-16字节，允许字母数字下划线)</span>
        </div>
        <div>
            密码:
            <input type="password" name="pwd">
            <span>密码(以字母开头，长度在6~18之间，只能包含字母、数字和下划线)</span>
        </div>
        <p>
            <input type="submit">
        </p>
        <script>
            let arr=[]
            let a={
                "text":/^[a-zA-Z][a-zA-Z0-9_]{4,15}$/,
                "password":/^[a-zA-Z]\w{5,17}$/
            }
            $("input").blur(function(){
                let type=$(this).prop("type")
                // console.log(type);
                let in_val=$(this).val()
                let rule=a[type]
                let bool1=rule.test(in_val)
                if (bool1) {
                    $(this).next().text("正确")
                }else{
                    $(this).next().text("不正确")
                }
                arr.push(bool1)
            })
            $("#login").submit(function(){
                
                if (arr.indexOf(false)==-1) {
                    return true;
                }else{
                    return false
                }
            })
        </script>
    </form>
</body>
</html>